package com.yuntu.service;

import com.yuntu.dao.Dev_UserMapper;
import com.yuntu.pojo.Dev_User;
import com.yuntu.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class Dev_UserServiceImpl implements Dev_UserService {
    @Autowired
    private Dev_UserMapper mapper;

    @Override
    public Dev_User login(String devName, String devPassword) {

        return mapper.login(devName,devPassword);
    }

    @Override
    public List<Dev_User> getPageAll(PageUtil<Dev_User> pageUtil) {
        List<Dev_User> list = new ArrayList<>();
        int count = mapper.getCount();
        System.out.println("------------count:"+count);
        pageUtil.setCounts(count);
        if (count>0){
            if (pageUtil.getPageindex()>pageUtil.getPagecount()){
                pageUtil.setPageindex(pageUtil.getPagecount());
            }
            list = mapper.getPageAll(pageUtil);
            pageUtil.setLists(list);
        }
        return list;
    }

    @Override
    public Dev_User selOne(String id) {
        return mapper.selOne(id);
    }

    @Override
    public boolean add(Dev_User dev_user) {
        boolean flag = false;
        if (mapper.add(dev_user)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean update(Dev_User dev_user) {
        boolean flag = false;
        if (mapper.update(dev_user)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public boolean delete(String id) {
        boolean flag = false;
        if (mapper.delete(id)>0){
            flag = true;
        }
        return flag;
    }

    @Override
    public Dev_User selectName(String devName) {
        return mapper.selectName(devName);
    }
}
